import { AuthRoute } from "~/src/typings/router";

// 固定路由
export const constroutes: AuthRoute.Route[] = [
  {
    name: 'root',
    path: '/',
    redirect: import.meta.env.VITE_APP_ROOTREDIRECT,
    meta:{
      title:'登录'
    }
  },
  {
    name: 'login',
    path: '/login',
    component: 'self',
    props: route => {
      const moduleType = (route.params.module as EnumType.LoginModuleKey) || 'pwd-login';
      return {
        module: moduleType
      };
    },
    meta: {
      title: '登录',
      dynamicPath: `/login/:module(${getLoginModuleRegExp()})?`
    }
  },
  {
    name: 'not-found-page',
    path: '/:pathMatch(.*)*',
    component: 'self',
    meta: {
      title: '未找到'
    }
  },
  {
    name: 'abnormal_404',
    path: '/404',
    component: 'self',
    meta: {
      title: '404'
    }
  }
];

/** 获取登录页面模块的动态路由的正则 */
export function getLoginModuleRegExp() {
  const modules: EnumType.LoginModuleKey[] = ['pwd-login', 'register'];
  return modules.join('|');
}
